package com.atguigu.service.eud_teacher.edu_subject.controller;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthRequest;
import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthResponse;
import com.atguigu.commonutils.R;
import com.atguigu.service.eud_teacher.edu_subject.utils.VideoPropertiesUtils;
import com.atguigu.service.eud_teacher.edu_subject.utils.initDefaultAcsClient;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.atguigu.service.eud_teacher.edu_subject.service.VideoService;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.List;


/**
 * 课程视频
 *
 * @author wuyao
 * @email 13918471632@163.com
 * @date 2021-03-23 12:12:26
 */
@RestController
@RequestMapping("/edu_subject/video")
@CrossOrigin
@Api(tags = "视频上传API")
public class VideoController {
    @Autowired
    private VideoService videoService;

    //上传视频
    @ApiOperation(value = "阿里视频点播上传功能")
    @PostMapping("/uploadVideos")
    public R uploadVideo(MultipartFile file) {
        HashMap<String, Object> map = videoService.uploadVideo(file);
        return R.ok().data(map);
    }

    //根据小节删除视频这里id是根据video_scouce_id
    @ApiOperation(value = "阿里云视频删除功能")
    @DeleteMapping("/deleteVideos/{id}")
    public R deleteVideo(@PathVariable String id) {
        videoService.deleteVideos(id);
        return R.ok();
    }

    //批量删除视频，根据章节远程调用删除
    @ApiOperation(value = "批量删除视频", notes = "根据章节远程调用删除")
    @DeleteMapping("/deleteForBatch")
    public R deleteForBatch(@RequestParam List videoIdList) {
        videoService.deleteForBatch(videoIdList);
        return R.ok();
    }


    @GetMapping("/getPlayAuth/{videoSourceId}")
    public R getVideoPlayAuth(@PathVariable String videoSourceId)  {
        return R.ok().data("playAuth", videoService.getAuth(videoSourceId));
    }
}

